home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / dev / ds5000.md / devStdFB.c < prev    next >
C/C++ Source or Header  |  1991-03-19  |  7KB  |  251 lines

  1. /* 
  2.  * devStdFB.c --
  3.  *
  4.  *    Routines for the /dev/stdfb device.
  5.  *
  6.  * Copyright 1991 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that this copyright
  10.  * notice appears in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/kernel/dev/ds5000.md/RCS/devStdFB.c,v 1.1 91/03/19 11:01:55 jhh Exp $ SPRITE (Berkeley)";
  18. #endif /* not lint */
  19.  
  20. #include <sprite.h>
  21. #include <devGraphicsInt.h>
  22. #include <proc.h>
  23. #include <dev/stdfb.h>
  24. #include <devStdFBInt.h>
  25.  
  26. /*
  27.  * Info on each process that has the device open.
  28.  */
  29. typedef struct OpenInfo {
  30.     List_Links            links;        /* Link them together. */
  31.     Proc_ControlBlock        *procPtr;    /* Process with fb open. */
  32.     Address            addr;        /* Address where fb is 
  33.                          * mapped. */
  34. } OpenInfo;
  35.  
  36. static List_Links    infoList;
  37.  
  38.  
  39. /*
  40.  *----------------------------------------------------------------------
  41.  *
  42.  *  DevStdFBOpen--
  43.  *
  44.  *    Open the device.
  45.  *
  46.  * Results:
  47.  *    SUCCESS if the device was opened, FAILURE otherwise
  48.  *
  49.  * Side effects:
  50.  *    None.
  51.  *
  52.  *----------------------------------------------------------------------
  53.  */
  54.  
  55. ReturnStatus
  56. DevStdFBOpen(devicePtr, useFlags, token, flagsPtr)
  57.     Fs_Device    *devicePtr;    /* Device info, unit number, etc. */
  58.     int        useFlags;    /* Flags from the stream being opened. */
  59.     Fs_NotifyToken    token;    /* Call-back token for input, unused here. */
  60.     int        *flagsPtr;    /* OUT: Device open flags. */
  61. {
  62.     int            slot;
  63.     Mach_SlotInfo    slotInfo;
  64.     char        *slotAddr;
  65.     OpenInfo        *infoPtr;
  66.     Proc_ControlBlock    *procPtr;
  67.     ReturnStatus    status = SUCCESS;
  68.  
  69.     procPtr = Proc_GetCurrentProc();
  70.     if (devicePtr->data == (ClientData) NIL) {
  71.     List_Init(&infoList);
  72.     devicePtr->data = (ClientData) &infoList;
  73.     }
  74.     slot = devicePtr->unit;
  75.     slotAddr = (char *) MACH_IO_SLOT_ADDR(slot);
  76.     status = Mach_GetSlotInfo(slotAddr + PMAGBA_ROM_OFFSET, &slotInfo);
  77.     if (status != SUCCESS) {
  78.     return status;
  79.     }
  80.     if (strcmp(slotInfo.vendor, "DEC") || 
  81.     strcmp(slotInfo.module, "PMAG-BA")) {
  82.     return FAILURE;
  83.     }
  84.     infoPtr = (OpenInfo *) malloc(sizeof(OpenInfo));
  85.     bzero((char *) infoPtr, sizeof(OpenInfo));
  86.     List_InitElement((List_Links *) infoPtr);
  87.     infoPtr->procPtr = procPtr;
  88.     infoPtr->addr = (Address) NIL;
  89.     List_Insert((List_Links *) infoPtr, LIST_ATFRONT(&infoList));
  90.     return status;
  91. }
  92.  
  93. /*
  94.  *----------------------------------------------------------------------
  95.  *
  96.  * DevStdFBMMap --
  97.  *
  98.  *    Map in the frame buffer.
  99.  *
  100.  * Results:
  101.  *    None.
  102.  *
  103.  * Side effects:
  104.  *    None.
  105.  *
  106.  *----------------------------------------------------------------------
  107.  */
  108.  
  109. ReturnStatus
  110. DevStdFBMMap(devicePtr, startAddr, length, offset, newAddrPtr)
  111.     Fs_Device    *devicePtr;    /* Device to map. */
  112.     Address    startAddr;    /* Where to map it.
  113.     int        length;        /* Number of bytes to map. */
  114.     int        offset;        /* Unused. */
  115.     Address    *newAddrPtr;    /* New address. */
  116. {
  117.     ReturnStatus    status = SUCCESS;
  118.     char        *fbAddr;
  119.     OpenInfo        *infoPtr = (OpenInfo *) NIL;
  120.     Proc_ControlBlock    *procPtr;
  121.     int            addr;
  122.     Boolean        found = FALSE;
  123.  
  124.     procPtr = Proc_GetCurrentProc();
  125.     LIST_FORALL((List_Links *) devicePtr->data, (List_Links *) infoPtr) {
  126.     if (infoPtr->procPtr == procPtr) {
  127.         if (infoPtr->addr != (Address) NIL) {
  128.         return FAILURE;
  129.         } else {
  130.         found = TRUE;
  131.         break;
  132.         }
  133.     }
  134.     }
  135.     if (!found) {
  136.     panic("DevStdFBMMap: info for proc 0x%x not found\n", procPtr);
  137.     return FAILURE;
  138.     }
  139.     fbAddr = (char *) MACH_IO_SLOT_ADDR(devicePtr->unit) + PMAGBA_BUFFER_OFFSET;
  140.     addr = (int) startAddr;
  141.     if (addr & VMMACH_OFFSET_MASK) {
  142.     addr += VMMACH_PAGE_SIZE;
  143.     addr &= ~VMMACH_OFFSET_MASK;
  144.     }
  145.     status = VmMach_UserMap(length, (Address) addr, (Address) fbAddr, FALSE,
  146.         (Address *) &addr);
  147.     if (status != SUCCESS) {
  148.     return status;
  149.     }
  150.     infoPtr->addr = (Address) addr;
  151.     *newAddrPtr = (Address) addr; 
  152. }
  153.  
  154. /*
  155.  *----------------------------------------------------------------------
  156.  *
  157.  *  DevStdFBIOControl --
  158.  *
  159.  *    Perform an IO control.
  160.  *
  161.  * Results:
  162.  *      GEN_NOT_IMPLEMENTED if io control not supported.  GEN_INVALID_ARG
  163.  *    if something else went wrong.  SUCCESS otherwise.
  164.  *    
  165.  *
  166.  * Side effects:
  167.  *    None.
  168.  *
  169.  *----------------------------------------------------------------------
  170.  */
  171.  
  172. ReturnStatus
  173. DevStdFBIOControl(devicePtr, ioctlPtr, replyPtr)
  174.     Fs_Device    *devicePtr;    /* Handle for device. */
  175.     Fs_IOCParam    *ioctlPtr;    /* Standard I/O Control parameter block. */
  176.     Fs_IOReply    *replyPtr;    /* Size of outBuffer and returned signal. */
  177. {
  178.     Dev_StdFBInfo    info;
  179.  
  180.     switch(ioctlPtr->command) {
  181.     case IOC_STDFB_INFO: {
  182.         if (ioctlPtr->outBufSize < sizeof (Dev_StdFBInfo)) {
  183.         return GEN_INVALID_ARG;
  184.         }
  185.         info.type = PMAGBA;
  186.         info.height = PMAGBA_HEIGHT;
  187.         info.width = PMAGBA_WIDTH;
  188.         info.planes = PMAGBA_PLANES;
  189.         bcopy((char *) &info, (char *) ioctlPtr->outBuffer, sizeof(info));
  190.         break;
  191.     }
  192.     default: 
  193.         return GEN_NOT_IMPLEMENTED;
  194.     }
  195.     return SUCCESS;
  196. }
  197.  
  198. /*
  199.  *----------------------------------------------------------------------
  200.  *
  201.  * DevStdFBClose --
  202.  *
  203.  *    Close the device
  204.  *
  205.  * Results:
  206.  *    None.
  207.  *
  208.  * Side effects:
  209.  *    None.
  210.  *
  211.  *----------------------------------------------------------------------
  212.  */
  213.  
  214. ReturnStatus
  215. DevStdFBClose(devicePtr, useFlags, openCount, writerCount)
  216.     Fs_Device   *devicePtr;        /* Information about device. */
  217.     int         useFlags;        /* Indicates whether stream being
  218.                      * closed was for reading and/or
  219.                      * writing:  OR'ed combination of
  220.                      * FS_READ and FS_WRITE. */
  221.     int         openCount;        /* # of times this particular stream
  222.                      * is still open. */
  223.     int         writerCount;        /* # of times this particular stream
  224.                      * is still open for writing. */
  225. {
  226.     ReturnStatus    status = SUCCESS;
  227.     OpenInfo        *infoPtr = (OpenInfo *) NIL;
  228.     Proc_ControlBlock    *procPtr;
  229.  
  230.     procPtr = Proc_GetCurrentProc();
  231.     LIST_FORALL((List_Links *) devicePtr->data, (List_Links *) infoPtr) {
  232.     if (infoPtr->procPtr == procPtr) {
  233.         break;
  234.     }
  235.     }
  236.     if (infoPtr->addr != (Address) NIL) {
  237.     status = VmMach_UserUnmap(infoPtr->addr);
  238.     if (status != SUCCESS) {
  239.         printf("DevFBClose: couldn't unmap frame buffer\n");
  240.         return FAILURE;
  241.     }
  242.     }
  243.     List_Remove((List_Links *) infoPtr);
  244.     free((char *) infoPtr);
  245.     if (openCount == 0) {
  246.     devicePtr->data = (ClientData) NIL;
  247.     }
  248.     return status;
  249. }
  250.  
  251.